from django.db import models
from django import template
from django.contrib import admin
from django.contrib.auth.models import User
from django.utils.translation import ugettext as _
from django.contrib.contenttypes.models import ContentType

# First, define the Manager subclass.
class TopicManager(models.Manager):
    def get_query_set(self):
        return super(TopicManager, self).get_query_set().exclude(summary="__NULL__")

class NullManager(models.Manager):
    def null_dimension(self):
        return self.get_or_create(summary="__NULL__")[0]


class Topic(models.Model):
    #Topic: Category to place issues, includes parent and child for hierarchical topics
    summary = models.CharField(max_length=140, unique=True)
    description = models.CharField(max_length=600, unique=True)
    submit_date = models.DateTimeField('date published', auto_now_add=True)
    parent = models.ForeignKey('self', null=True, blank=True)
    children = models.IntegerField(_('Children'), default=0)
    more_info = models.CharField(max_length=20, blank=True, null=True)
    is_featured = models.BooleanField(default=False)
    objects = NullManager()
    clean_objects = TopicManager()

    def __unicode__(self):
        return self.summary

    def get_verbose_name(self):
        return 'topic'

    def is_root(self):
        return True

    def get_absolute_url(self):
        content_type = ContentType.objects.get_for_model(self.__class__)
        path = "/index.html#item" + "/_t" + str(content_type.pk) + "/_o" + str(self.pk)
        return path

admin.site.register(Topic)
